<template>
  <div class="app-container">
    <!--表单-->
    <el-form :inline="true" class="demo-form-inline">
      <!-- <el-form-item aria-disabled="false">
          <el-select v-model="searchObj.type" clearable placeholder="请选择">
            <el-option label="学员登录数统计" value="login_num" />
            <el-option label="学员注册数统计" value="register_num" />
            <el-option label="课程播放数统计" value="video_view_num" />
            <el-option label="每日课程数统计" value="course_num" />
          </el-select>
        </el-form-item> -->
      <el-form-item>
        <el-date-picker
          v-model="searchObj.begin"
          type="date"
          placeholder="选择开始日期"
          value-format="yyyy-MM-dd"
        />
      </el-form-item>
      <el-form-item>
        <el-date-picker
          v-model="searchObj.end"
          type="date"
          placeholder="选择截止日期"
          value-format="yyyy-MM-dd"
        />
      </el-form-item>
      <el-button
        :disabled="btnDisabled"
        type="primary"
        icon="el-icon-search"
        @click="showChart()"
        >查询</el-button
      >
    </el-form>
    <div class="chart-container">
      <div id="chart" class="chart" style="height: 500px; width: 100%" />
    </div>
  </div>
</template>
  <script>
import echarts from "echarts";
import staApi from "@/api/sta";
export default {
  data() {
    return {
      searchObj: {
        begin: "",
        end: "",
      },
      btnDisabled: false,
      chart: null,
      title: "",
      xData: [],
      yData: [],
    };
  },
  methods: {
    showChart() {
      staApi.getDataSta(this.searchObj).then((response) => {
        // console.log("*****************" + response);
        this.yData = response.data.LoginNumDataList;     //登录数
        this.xData = response.data.date_calculatedList;  //时间跨度
        this.aData = response.data.RegisterNumDataList;  //注册数
        this.bData = response.data.VideoViewNumList;     //观看数
        this.cData = response.data.CourseNumDataList;    //新增课程数

        console.log("******时间跨度******" + this.xData);
        console.log("*******登录数****" + this.yData);
        console.log("*******注册数******" + this.aData);
        console.log("********观看数*****" + this.bData);
        console.log("*******新增课程数****" + this.cData);

        //调用下面生成图表的方法，改变值
        this.setChart();
      });
    },
    setChart() {
      // 基于准备好的dom，初始化echarts实例
      this.chart = echarts.init(document.getElementById("chart"));
      // console.log(this.chart)

      // 指定图表的配置项和数据
      var option = {
        title: {
          text: "数据统计",
        },
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "cross",
            label: {
              backgroundColor: "#6a7985",
            },
          },
        },
        // -------图表缩放开始-----------------------------------------------------------------------------------------------------
        dataZoom: [
          {
            show: true,
            height: 30,
            xAxisIndex: [0],
            bottom: 30,
            start: 10,
            end: 80,
            handleIcon:
              "path://M306.1,413c0,2.2-1.8,4-4,4h-59.8c-2.2,0-4-1.8-4-4V200.8c0-2.2,1.8-4,4-4h59.8c2.2,0,4,1.8,4,4V413z",
            handleSize: "110%",
            handleStyle: {
              color: "#d3dee5",
            },
            textStyle: {
              color: "#fff",
            },
            borderColor: "#90979c",
          },
          {
            type: "inside",
            show: true,
            height: 15,
            start: 1,
            end: 35,
          },
        ],
        // --------图表缩放结束--------------------------------------------------------------------------------------
        legend: {
          data: ["登录数", "注册数", "观看数", "新增课程数"],
        },
        toolbox: {
          feature: {
            saveAsImage: {},
          },
        },
        grid: {
          left: "3%",
          right: "4%",
          bottom: "3%",
          containLabel: true,
        },
        xAxis: [
          {
            type: "category",
            boundaryGap: false,
            data: this.xData
          },
        ],
        yAxis: [
          {
            type: "value",
          },
        ],
        series: [
          {
            name: "登录数",
            type: "line",
            stack: "Total",
            areaStyle: {},
            emphasis: {
              focus: "series",
            },
            data: this.yData
          },
          {
            name: "注册数",
            type: "line",
            stack: "Total",
            areaStyle: {},
            emphasis: {
              focus: "series",
            },
            data: this.aData
          },
          {
            name: "观看数",
            type: "line",
            stack: "Total",
            areaStyle: {},
            emphasis: {
              focus: "series",
            },
            data: this.bData
          },
          {
            name: "新增课程数",
            type: "line",
            stack: "Total",
            areaStyle: {},
            emphasis: {
              focus: "series",
            },
            data: this.cData
          },
        //   {
        //     name: "Search Engine",
        //     type: "line",
        //     stack: "Total",
        //     label: {
        //       show: true,
        //       position: "top",
        //     },
        //     areaStyle: {},
        //     emphasis: {
        //       focus: "series",
        //     },
        //     data: [820, 932, 901, 934, 1290, 1330, 1320],
        //   },
        ],
      };

      this.chart.setOption(option);
    },
  },
};
</script>